<template>
	<view>
		<uni-nav-bar title="老板账户" left-icon="left" @clickLeft="redirectTo('index/mine')" :fixed="true" statusBar></uni-nav-bar>
		<environment></environment>
		<view class="account_top">
			<text>老板账户(元)</text>
			<text>{{userInfo.empower_money}}</text>
		</view>
		<!-- 可用账户 -->
		<view class="account">
		  <view class="account_title" @click="carexplain('1')">
		    <view class="title">
		      <text>老板账户</text>
		      <text></text>
		    </view>
		    <uni-icons type="help-filled" size="22" color="#D1D1D1"></uni-icons>
		  </view>
		  <!-- 可用账户列表 -->
		  <AccountList :friendInfor="friendInfor" :pageHeight="pageHeight"></AccountList>
		</view>
		<!-- 弹出提示框 -->
		<uni-popup ref="popup" type="center" :is-mask-click="false">
		  <view class="popups">
		    <view>{{ explainAll.title }}</view>
		    <view>{{ explainAll.content }}</view>
		    <view @click="close()">我知道了</view>
		  </view>
		</uni-popup>
	</view>
</template>

<script setup lang="ts">
	import { Ref,ref,onMounted } from 'vue';
	import { carfriendUserInfo } from '@/gql/carAuthorized';
	import { authorMe } from '@/gql/user';
	import environment from '@c/pobulic/environment.vue';
	import { redirectTo } from '@/utils/navigator';
	import { showLoading } from '@/utils/prompt';
	import { useUserStore } from '@/stores/user';
	import { toPublish } from '@mqtt';
	import { onShow } from '@dcloudio/uni-app';
	import AccountList from '@c/authorized/accountList.vue';
	import { getDriverID } from '@/stores/driverID';
	const driver_id = getDriverID();
	const userInfo = useUserStore();
	const explainAll = ref({
	  title: '',
	  content: '',
	});
	const friendInfor: Ref<any[]> = ref([]);
	const pageHeight=ref('')
	const popup = ref(null);
	onMounted(() => {
	  uni.getSystemInfo({
	    success: function(res) {
	      pageHeight.value = (res.windowHeight - 260).toString();
	    },
	  });
	});
	onShow(() => {
	  init();
	});
	function init() {
	  showLoading('加载中');
	  const payload = {
	    query: carfriendUserInfo,
	    variables: { driver_id},
	  };
	  toPublish('ql/driver/getEmpowerListToMe', payload, (obj: any) => {
	    const { data } = obj;
	    friendInfor.value = data.empower_list_for_me2;
	  });
	}
	function carexplain(type: string) {
	  popup.value.open();
	  const payload = {
	    query: authorMe,
	    variables: {
	      code: type === '1' ? 'kyzhjd' : 'wdsqjd',
	    },
	  };
	  toPublish('ql/driver/getMyblock', payload, (obj: any) => {
	    const { data } = obj;
	    explainAll.value = data.get_myblock;
	  });
	}
	function close() {
	  popup.value.close();
	}
</script>
<style scoped lang="less">
@import url('../authorized/less/authorizedList.less');
</style>